package com.grom.service;

import java.util.List;

import com.grom.dao.GcmsUserDao;
import com.grom.po.GcmsUser;

public interface GcmsUserService {
	GcmsUserService instance = new GcmsUserService() {
		public List<GcmsUser> getAllUser() {
			return GcmsUserDao.instance.getAllUsers();
		}

		public void add(GcmsUser user) {
			GcmsUserDao.instance.add(user);
		}

		public void update(GcmsUser user) {
			GcmsUserDao.instance.update(user);
		}

		public void delete(GcmsUser user) {
			GcmsUserDao.instance.delete(user);
		}

		public List<GcmsUser> selectByCondition(String sql) {
			return GcmsUserDao.instance.selectByCondition(sql);
		}

		public GcmsUser getUserByID(String id) {
			return GcmsUserDao.instance.getUserByID(id);
		}

		public boolean isUserExist(String userName) {
			String sql = "select * from gcmsuser where username='" + userName
					+ "'";
			List<GcmsUser> result = GcmsUserDao.instance.selectByCondition(sql);
			if (result != null && result.size() > 0) {
				return true;
			}
			return false;
		}

		public boolean isUserCorrect(String userName, String password) {
			String sql = "select * from gcmsuser where username='" + userName
					+ "' and password = '" + password + "'";
			List<GcmsUser> result = GcmsUserDao.instance.selectByCondition(sql);
			if (result != null && result.size() > 0) {
				return true;
			}
			return false;
		}

		public GcmsUser getUserByUserName(String userName) {
			String sql = "select * from gcmsuser where username='" + userName
					+ "'";
			List<GcmsUser> result = GcmsUserDao.instance.selectByCondition(sql);
			if (result == null || result.size() == 0) {
				return new GcmsUser();
			}
			return result.get(0);
		}

		public List<GcmsUser> getUsersByDepartment(String departmentId) {
			String sql = "select * from gcmsuser where id in (select userid from relationdeptouser where departmentID = '"
					+ departmentId + "')";
			List<GcmsUser> result = GcmsUserDao.instance.selectByCondition(sql);
			return result;
		}
	};

	List<GcmsUser> getAllUser();

	List<GcmsUser> getUsersByDepartment(String departmentId);

	GcmsUser getUserByID(String id);

	GcmsUser getUserByUserName(String userName);

	void add(GcmsUser user);

	void update(GcmsUser user);

	void delete(GcmsUser user);

	List<GcmsUser> selectByCondition(String sql);

	boolean isUserExist(String userName);

	boolean isUserCorrect(String userName, String password);
}
